//-----------------------------------------------------------------------
// <copyright file="DeleteFile.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
// </copyright>
// <summary>Deletes the specified file from the Web Service Extensions (IIS6 or later).</summary>
//-----------------------------------------------------------------------
namespace Microsoft.Sdc.Tasks.Web.ServiceExtension
{
    using System;
    using Microsoft.Sdc.Tasks.Configuration.Web;
    using Microsoft.Build.Framework;

    /// <summary>
    /// Deletes the specified web service extension file (IIS6 or later)
    /// </summary>
    /// <remarks>
    /// <code><![CDATA[
    ///     <Web.ServiceExtension.DeleteFile Path="path" />]]></code>
    /// <para>where:</para>
    /// <para><i>path (Required)</i></para>
    /// <para>Fully specified path to the extension file</para>
    /// </remarks>
    /// <example>
    /// <code><![CDATA[
    /// <Project>
    ///     <Target Name="Test" >
    ///         <Web.ServiceExtension.DeleteFile 
    ///             Path="c:\myweb\myextensionservice.dll" 
    ///         />
    ///     </Target>
    /// </Project>
    /// ]]></code>    
    /// </example>    
    public class DeleteFile : TaskBase
    {
        private string path;
        private string machineName = "localhost";

        /// <summary>
        /// Machine to operate on
        /// </summary>
        public string MachineName
        {
            get { return this.machineName; }
            set { this.machineName = value; }
        }

        /// <summary>
        /// Path to the web extension service executable
        /// </summary>
        /// <value>Fully specified path to the web extension service file</value>
        [Required]
        public string Path
        {
            get { return (this.path ?? String.Empty); }
            set { this.path = value; }
        }

        /// <summary>
        /// Performs the action of this task.
        /// </summary>
        protected override void InternalExecute()
        {
            Log.LogMessageFromResources("Web.RemoveFileFromWebServiceExtension", this.path);
            WebServiceExtension.DeleteFile(this.path, this.MachineName);
        }
    }
}